import Vue from 'vue'
import Router from 'vue-router'
import Vbody from '@/components/Vbody'
import Vindex from '@/components/Vindex'
import xadmin_menu from '@/components/xadmin_menu'
import xadmin_index from '@/components/xadmin_index'
import xadmin_change from '@/components/xadmin_change'
import xadmin_add from '@/components/xadmin_add'
import xadmin_list from '@/components/xadmin_list'
import login from '@/components/login'


Vue.use(Router)
// 让vue-router没有回调函数
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}



export default new Router({
  routes: [
    {
      path: '/',
      name: 'Vindex',
      component: Vindex,
      meta:{
        requireAuth:true
      },
      children:[
        {
          path: '/',
          name: 'Vbody',
          component:Vbody,
          meta:{
            requireAuth:true
          }
        },
        {
          path: 'xadmin/:app_id/',
          name: 'xadmin',
          component: xadmin_menu,
          meta:{
            requireAuth:true
          },
          children:[
            {
              path: ':app_name/:label_name/list',
              name: 'xadmin_list',
              component:xadmin_list,
              meta:{
                requireAuth:true
              }
            },
            {
              path: ":app_name/:label_name/:id/change",
              name: 'xadmin_change',
              component:xadmin_change,
              meta:{
                requireAuth:true
              }
            },
            {
              path: ":app_name/:label_name/add",
              name: 'xadmin_add',
              component: xadmin_add,
              meta:{
                requireAuth:true
              }
            }
          ]
        }

      ]
    },
    {
      path: '/login',
      name: 'login',
      component: login
    }
  ]
})
